import { TeamBuyItem } from "./TeamBuyItem";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { FontUtil } from "../../../common/font/FontUtil";
import { Language } from "../../../../extend/language/Language";
import { GTextFormat } from "../../../common/GTextFormat";
import { SecTimerView } from "../common/SecTimerView";
import { FilterConst } from "../../../component/gconst/FilterConst";
type int = number;
//class TopBody
    
    export  class TopBody /* flash.events.EventDispatcher */
    {
        constructor(arg1: Object /* flash.display.Sprite */)
        {
            
            this.itemsBox = new Object /* flash.display.Sprite */();
            this.poolObjectList = new Array<any>();
            this.box = arg1;
            this.createTop();
            return;
        }

        public upDataMyJointGroups(arg1: Array<any>): void
        {
            var loc2=null;
            var loc4=null;
            var loc1=arg1.length;
            var loc3=0;
            while (loc3 < loc1) 
            {
                loc4 = arg1[loc3];
                loc2 = this.getTeamBuyItemByItemCode[loc4.itemCode];
                loc2.hasJoin = true;
                loc2.firstBuyPirce = loc4.buyPrice;
                ++loc3;
            }
            if (this.itemsBox.numChildren > this.hasSelectItemIndex) 
            {
                loc2 = this.itemsBox.getChildAt(this.hasSelectItemIndex) as TeamBuyItem;
                this.changeGroupInfoHander(null, loc2);
            }
            return;
        }

        public upDataGroups(arg1: Array<any>): void
        {
            var loc2=null;
            var loc9=null;
            this.getTeamBuyItemByItemCode = new Map<any, any> /* flash.utils.Dictionary */(false);
            while (this.itemsBox.numChildren > 0) 
            {
                loc2 = this.itemsBox.getChildAt(0) as TeamBuyItem;
                this.disposeObject(loc2);
            }
            var loc1=arg1.length;
            var loc3=33;
            var loc4=125;
            var loc5=670;
            var loc6=(loc1 - 1) * loc3 + loc4 * loc1;
            var loc7=int((loc5 - loc6) * 0.5);
            var loc8=0;
            while (loc8 < loc1) 
            {
                loc9 = arg1[loc8];
                loc2 = this.getPoolObject();
                this.itemsBox.addChild(loc2);
                loc2.updateData(loc9, loc8);
                loc2.x = loc7 + (loc3 + loc4) * loc8;
                this.getTeamBuyItemByItemCode[loc9.itemCode] = loc2;
                ++loc8;
            }
            return;
        }

        public getItemByIndex(arg1: int): TeamBuyItem
        {
            if (arg1 >= this.itemsBox.numChildren) 
            {
                return null;
            }
            return this.itemsBox.getChildAt(arg1) as TeamBuyItem;
        }

        /* internal  */changeGroupInfoHander(arg1: Object /* flash.events.Event */, arg2: TeamBuyItem=null): void
        {
            var loc3=null;
            var loc1=this.itemsBox.numChildren;
            var loc2=0;
            while (loc2 < loc1) 
            {
                (loc3 = this.itemsBox.getChildAt(loc2) as TeamBuyItem).select = false;
                ++loc2;
            }
            if (arg1) 
            {
                arg2 = TeamBuyItem(arg1.currentTarget);
            }
            arg2.select = true;
            this.hasSelectItemIndex = arg2.itemIdex;
            this.dispatchEvent(new Object /* flash.events.Event */("#change#"));
            return;
        }

        /* internal  */createTop(): void
        {
            ObjCreate.createFlowerBg(17, 38, 674, 355, this.box, true, "LT,RT");
            var loc1=ObjCreate.createBitmap(ImagesConst.RechargeFlwBg, 137, 50, this.box);
            var loc2=ObjCreate.createBitmap(ImagesConst.RechargeFlwBg, 588, 50, this.box);
            loc2.rotationY = -180;
            ObjCreate.createBg(90, 73, 545, 1, this.box, ImagesConst.KillUserLine);
            ObjCreate.createBg(51, 116, 607, 1, this.box, ImagesConst.KillUserLine);
            ObjCreate.createBg(51, 116, 607, 1, this.box, ImagesConst.KillUserLine);
            ObjCreate.createBg(51, 304, 607, 1, this.box, ImagesConst.KillUserLine);
            ObjCreate.createBg(193, 332, 340, 1, this.box, ImagesConst.KillUserLine);
            var loc3=GlobalStyle.textFormatRed;
            loc3.font = FontUtil.EmbedTitleName;
            loc3.size = 22;
            ObjCreate.createEmbedTextFiled(Language.getString(85031), 232, 86, 172, 20, this.box, loc3);
            ObjCreate.createTextField(Language.getString(85032), 474, 94, 172, 20, this.box, GlobalStyle.textFormat2);
            ObjCreate.setObjAttri(this.itemsBox, 19, 126, -1, -1, this.box);
            var loc4;
            (loc4 = new GTextFormat(FontUtil.EmbedNumberName, 22, GlobalStyle.color5Uint)).letterSpacing = 2;
            this.curTimer = new SecTimerView();
            this.curTimer.embedFonts = true;
            this.curTimer.defaultTextFormat = loc4;
            this.curTimer.setParse("HH: mm: ss");
            this.curTimer.filters = [FilterConst.glowFilter];
            this.curTimer.mouseEnabled = false;
            ObjCreate.setObjAttri(this.curTimer, 354, 86, 116, 20, this.box);
            return;
        }

        /* internal  */getPoolObject(): TeamBuyItem
        {
            var loc1=null;
            if (this.poolObjectList.length != 0) 
            {
                loc1 = this.poolObjectList.shift();
            }
            else 
            {
                loc1 = new TeamBuyItem();
                loc1.addEventListener(flash.events.MouseEvent.CLICK, this.changeGroupInfoHander);
            }
            return loc1;
        }

        /* internal  */disposeObject(arg1: TeamBuyItem): void
        {
            if (arg1.parent) 
            {
                arg1.parent.removeChild(arg1);
            }
            arg1.select = false;
            arg1.hasJoin = false;
            this.poolObjectList.push(arg1);
            return;
        }

        /* internal */ /* var */box: Object /* flash.display.Sprite */;

        public /* var */curTimer: SecTimerView;

        /* internal */ /* var */itemsBox: Object /* flash.display.Sprite */;

        public /* var */hasSelectItemIndex: int=0;

        /* internal */ /* var */getTeamBuyItemByItemCode: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */poolObjectList: Array<any>;
    }
